package com.vf.admin.client.dao;

import com.vf.admin.common.db.BaseDao;
import com.vf.admin.common.splitpage.SplitPageBean;
import com.vf.admin.miaodong.entity.AppBanner;
import com.vf.admin.miaodong.entity.AppCharmLevel;
import com.vf.admin.miaodong.entity.AppHelp;
import com.vf.admin.utils.StringEx;
import org.springframework.stereotype.Repository;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

@Repository
public class AppCharmLevelDao extends BaseDao<AppCharmLevel> {

    public AppCharmLevel levelInfo(Integer level) {
        ArrayList<Object> paramList = new ArrayList<>();
        StringBuilder sbStr = new StringBuilder("select * from app_charm_level where level = ? ");
        paramList.add(level);
        String sql = sbStr.toString();
        return this.queryObj(sql, paramList, AppCharmLevel.class);
    }

    public List<AppCharmLevel> list(AppCharmLevel appCharmLevel, SplitPageBean splitPage) {
        StringBuilder sbStr = new StringBuilder("select * from app_charm_level where 1=1");
        ArrayList<Object> paramList = new ArrayList<>();

        if (StringEx.isNotNull(appCharmLevel.getLevel())) {
            sbStr.append(" and level = ?");
            paramList.add(appCharmLevel.getLevel());
        }
        if (StringEx.isNotNull(appCharmLevel.getSurfaceTitle())) {
            sbStr.append(" and surfaceTitle like ?");
            paramList.add("%" + appCharmLevel.getSurfaceTitle() + "%");
        }
        sbStr.append(" order by level asc");

        return this.queryList(sbStr.toString(), paramList, AppCharmLevel.class, splitPage);
    }

    public void saveOrUpdate(AppCharmLevel appCharmLevel) {
        if (appCharmLevel.getId() == null || appCharmLevel.getId() == 0) {
            this.add(appCharmLevel);
        } else {
            this.update(appCharmLevel);
        }
    }

    public AppCharmLevel getById(Integer id) {
        ArrayList<Object> paramList = new ArrayList<>();
        String sql = "select * from app_charm_level where id = ? ";
        paramList.add(id);
        return this.queryObj(sql, paramList, AppCharmLevel.class);
    }

    public void deleteById(Integer id){
        ArrayList<Object> paramList = new ArrayList<>();
        String sql = "delete  from app_charm_level where id = ? ";
        paramList.add(id);
        this.del(sql,paramList);
    }
}
